-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature gating subsystems via #[cfg]
#41
Feature gating subsystems via #[cfg]
#41
Conversation
@@ -15,6 +15,7 @@ declarative. | |||
#[subsystem(MsgA, sends: [MsgB])] | |||
sub_a: AwesomeSubSysA, | |||
|
|||
#[cfg(any(feature = "feature1", feature = "feature2"))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
Co-authored-by: Bernhard Schuster <bernhard@ahoi.io>
assert_eq!("any (not (feature = \"no\") , any (feature = \"any2\" , feature = \"any1\") , all (feature = \"f2\" , feature = \"f1\" , feature = \"f3\"))" | ||
, to_parse.to_token_stream().to_string()); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very very nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few small nits, generally looks very good!
Q: do we want to allow arbitrary #[]
macros eventually? I.e. copying derive
over to the generated struct
only and keeping any other ones on all items. But that's for another time I think.
Not sure I understand, how could this be used? |
In this PR I introduce guarding of subsystems via features.
Supported syntax:
Basically this allows re-use of one orchestra in scenarios where it is not needed to run all subsystems. The
#cfg
attribute macro currently supportsany
,all
,not
andfeature = "something"
.Limitations
Feature unification. The current implementation is not very useful when you have a large workspace, and different crates depend on the defined orchestra with different features enabled.
Performance depends on the number of unique cfg expressions defined in the crate. With the current design of the orchestra builder, I have to build distinct feature combinations for the builder. This scales with O(2^n) where n is the number of distinct feature expressions. I tested a bit and impact is starting to show at around 7 different feature expressions.